<html>
<head><meta charset="utf-8"><title>SIMD pointers monomorphization error? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/SIMD.20pointers.20monomorphization.20error.3F.html">SIMD pointers monomorphization error?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="241072019"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/SIMD%20pointers%20monomorphization%20error%3F/near/241072019" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/SIMD.20pointers.20monomorphization.20error.3F.html#241072019">(Jun 01 2021 at 20:38)</a>:</h4>
<p>Hi! I'm getting type errors where I'm trying to get a vector of pointers to realize it's Valid <span aria-label="tm" class="emoji emoji-2122" role="img" title="tm">:tm:</span> in some code I'm hacking on. I've compared several examples and now I'm at the point where I think it's an issue in the compiler. Specifically, my example is:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[derive(Debug,Copy,Clone)]</span><span class="w"></span>
<span class="cp">#[repr(simd)]</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">SimdConst</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">LANES</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">([</span><span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="n">T</span><span class="p">;</span><span class="w"> </span><span class="n">LANES</span><span class="p">]);</span><span class="w"></span>
</code></pre></div>
<p>If anyone knows where to start looking to fix this in terms of making this legal in the compiler, I'd love some ideas! I think this happens during SIMD monomorphization but I believe this might be a pre-monomorphization error of some kind of failed typechecking. I filed this as issue <a href="https://github.com/rust-lang/rust/issues/85915">https://github.com/rust-lang/rust/issues/85915</a></p>



<a name="241075966"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/SIMD%20pointers%20monomorphization%20error%3F/near/241075966" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tm <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/SIMD.20pointers.20monomorphization.20error.3F.html#241075966">(Jun 01 2021 at 21:08)</a>:</h4>
<p>The pointers seems to be simply rejected despite the error message suggesting otherwise: <a href="https://github.com/rust-lang/rust/blob/7f9ab0300cd66f6f616e03ea90b2d71af474bf28/compiler/rustc_typeck/src/check/check.rs#L1220">https://github.com/rust-lang/rust/blob/7f9ab0300cd66f6f616e03ea90b2d71af474bf28/compiler/rustc_typeck/src/check/check.rs#L1220</a> (<code>is_machine</code> does not include pointers).</p>



<a name="241079411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/SIMD%20pointers%20monomorphization%20error%3F/near/241079411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/SIMD.20pointers.20monomorphization.20error.3F.html#241079411">(Jun 01 2021 at 21:38)</a>:</h4>
<p><span class="user-mention silent" data-user-id="352985">tm</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/SIMD.20pointers.20monomorphization.20error.3F/near/241075966">said</a>:</p>
<blockquote>
<p>The pointers seems to be simply rejected despite the error message suggesting otherwise: <a href="https://github.com/rust-lang/rust/blob/7f9ab0300cd66f6f616e03ea90b2d71af474bf28/compiler/rustc_typeck/src/check/check.rs#L1220">https://github.com/rust-lang/rust/blob/7f9ab0300cd66f6f616e03ea90b2d71af474bf28/compiler/rustc_typeck/src/check/check.rs#L1220</a> (<code>is_machine</code> does not include pointers).</p>
</blockquote>
<p>Is that so...?</p>
<blockquote>
<p><div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[inline]</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">is_machine</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kt">bool</span> <span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="fm">matches!</span><span class="p">(</span><span class="bp">self</span><span class="p">.</span><span class="n">kind</span><span class="p">(),</span><span class="w"> </span><span class="n">Int</span><span class="p">(</span><span class="o">..</span><span class="p">)</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">Uint</span><span class="p">(</span><span class="o">..</span><span class="p">)</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">Float</span><span class="p">(</span><span class="o">..</span><span class="p">))</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
</code></pre></div><br>
</p>
</blockquote>
<p>ah, lovely.</p>



<a name="241079517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/SIMD%20pointers%20monomorphization%20error%3F/near/241079517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/SIMD.20pointers.20monomorphization.20error.3F.html#241079517">(Jun 01 2021 at 21:40)</a>:</h4>
<p>so the full parameters are accepted because they're parameters, and the machine types are accepted because they're explicitly allowed, but a pointer type is not recognized.</p>



<a name="241079807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/SIMD%20pointers%20monomorphization%20error%3F/near/241079807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/SIMD.20pointers.20monomorphization.20error.3F.html#241079807">(Jun 01 2021 at 21:43)</a>:</h4>
<p>Obviously this has to be fixed, raw pointers should be explicitly allowed, my question now is, I guess, which pointers I want to legalize. Conservatively: raw pointers. Hilariously: any pointer.</p>



<a name="241080344"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/SIMD%20pointers%20monomorphization%20error%3F/near/241080344" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/SIMD.20pointers.20monomorphization.20error.3F.html#241080344">(Jun 01 2021 at 21:50)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ptrx2</span><span class="p">(</span><span class="o">&amp;</span><span class="n">v</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">v</span><span class="p">);</span><span class="w"></span>
</code></pre></div>
<p>...well, that monomorphizes successfully.</p>



<a name="241080367"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/SIMD%20pointers%20monomorphization%20error%3F/near/241080367" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/SIMD.20pointers.20monomorphization.20error.3F.html#241080367">(Jun 01 2021 at 21:50)</a>:</h4>
<p>...I have absolutely no idea what I'd do with it, but it does.</p>



<a name="241082879"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/SIMD%20pointers%20monomorphization%20error%3F/near/241082879" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/SIMD.20pointers.20monomorphization.20error.3F.html#241082879">(Jun 01 2021 at 22:19)</a>:</h4>
<blockquote>
<p>error: monomorphising SIMD type <code>ptrx2&lt;fn(i32) -&gt; i32 {incr}&gt;</code> with a non-primitive-scalar (integer/float/pointer) element type <code>fn(i32) -&gt; i32 {incr}</code></p>
</blockquote>
<p>Okay, okay, so no function pointers, but refs are fair game I guess.</p>



<a name="241083024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/SIMD%20pointers%20monomorphization%20error%3F/near/241083024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/SIMD.20pointers.20monomorphization.20error.3F.html#241083024">(Jun 01 2021 at 22:21)</a>:</h4>
<blockquote>
<p>error: monomorphising SIMD type <code>ptrx2&lt;&amp;[i32]&gt;</code> with a non-primitive-scalar (integer/float/pointer) element type <code>&amp;[i32]</code></p>
</blockquote>
<p>Also no slices, cool!</p>



<a name="241090990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/SIMD%20pointers%20monomorphization%20error%3F/near/241090990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/SIMD.20pointers.20monomorphization.20error.3F.html#241090990">(Jun 02 2021 at 00:04)</a>:</h4>
<p>And now it's a PR! Thank you! <a href="https://github.com/rust-lang/rust/pull/85919">https://github.com/rust-lang/rust/pull/85919</a></p>



<a name="241296109"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/SIMD%20pointers%20monomorphization%20error%3F/near/241296109" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Giacomo Stevanato <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/SIMD.20pointers.20monomorphization.20error.3F.html#241296109">(Jun 02 2021 at 18:03)</a>:</h4>
<p>What happens with a <code>*const [i32]</code>?</p>



<a name="241305399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/SIMD%20pointers%20monomorphization%20error%3F/near/241305399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/SIMD.20pointers.20monomorphization.20error.3F.html#241305399">(Jun 02 2021 at 19:10)</a>:</h4>
<p><span class="user-mention silent" data-user-id="338379">Giacomo Stevanato</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/SIMD.20pointers.20monomorphization.20error.3F/near/241296109">said</a>:</p>
<blockquote>
<p>What happens with a <code>*const [i32]</code>?</p>
</blockquote>
<p>it fails like it should, see <a href="https://github.com/workingjubilee/rustc/pull/1/commits/c0ca38288f5d56ffaae1c58f77af5915b8a3133b">https://github.com/workingjubilee/rustc/pull/1/commits/c0ca38288f5d56ffaae1c58f77af5915b8a3133b</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>